<template>
  <div class="page401">
    <div class="statusImg">
      <img :src="img_401" alt="401" />
    </div>
    <div class="statuesMsg">
      <h3>无访问权限，错误代码 401</h3>
      <p class="des">暂未获得授权访问许可，请联系管理员</p>
      <el-space>
        <el-button type="primary" @click="backHome">返回</el-button>
        <el-button type="primary" @click="loginOut">重新登录</el-button>
      </el-space>
    </div>
  </div>
</template>

<script lang="ts" setup>
  import img_401 from '@/assets/images/httpStatus/401.png';
  import { useRouter } from 'vue-router';
  import { clearStorage, getStorage } from '@/utils/cache';
  import { loginOut as lgout } from '@/api/common';

  const router = useRouter();
  const backHome = () => router.replace('/');
  const loginOut = () => {
    if (!getStorage('token')) {
      clearStorage();
      router.replace('/login');
    } else {
      lgout().then(() => {
        clearStorage();
        router.replace('/login');
      });
    }
  };
</script>

<style rel="stylesheet/scss" lang="less" scoped>
  .page401 {
    background: #f1f2f7;
    height: 100%;
    display: flex;
    align-items: center;
    flex-direction: row;
    justify-content: center;

    .statusImg {
      width: 40%;
      display: flex;
      align-items: center;
      justify-content: center;
      img {
        max-width: 100%;
        max-height: 100%;
      }
    }
    .statuesMsg {
      padding-left: 15px;
      h3 {
        color: var(--el-color-primary);
        font-size: 18px;
        font-weight: bold;
        margin-bottom: 12px;
      }
      .des {
        font-size: 14px;
        margin-bottom: 12px;
        color: #333333;
      }

      .btns {
        font-size: 14px;
      }
    }
  }
</style>
